<?php

namespace app\common\library;

class OrderSn
{
    public static function create(int $salt = 0, $pre = 'H', $len = 23): string
    {
        $salt = $salt <= 9999 ? $salt : substr($salt, -4);
        $order_sn = $pre . date('YmdHis') . $salt;
        $randStrLen = $len - strlen($order_sn);
        $randStr = random_int(pow(10, ($randStrLen - 1)), pow(10, $randStrLen) - 1);
        return $order_sn.$randStr;
    }
}